out_name = getSaveFileName caption:"Export to Text File"\
	types:"Text Files(*.txt)|*.txt"\
	initialDir:(getDir #export)\
	historyCategory:"ExportTextFiles"
if out_name != undefined then 
(
	out_file = createfile out_name
	countObjScene = 0
	for tmpObj in objects do
	(
		if classof tmpObj != Dummy then
		(
			countObjScene = countObjScene + 1
		)
	)
	format "%\n" countObjScene to:out_file
	for tmpObj in objects do
	(
		if classof tmpObj != Dummy then
		(
			tmesh = snapshotAsMesh tmpObj
			if tmpObj.material != undefined then
				texture = getFilenameFile tmpObj.material.diffusemap.filename + getFilenameType tmpObj.material.diffuseMap.filename
			else
				texture = "undefined.bmp"
			num_verts = tmesh.numverts 
			num_tverts = tmesh.numtverts 
			num_faces = tmesh.numfaces
			format "% % % %\n" num_verts num_tverts num_faces texture to:out_file
		 
			for v = 1 to num_verts do
			(
				vert = getVert tmesh v
				format "%\t%\t%\t\t" vert.x vert.y vert.z to:out_file
				normal = getNormal  tmesh v
				format "%\t%\t%\n" normal.x normal.y normal.z to:out_file
			)
			format "\n" to:out_file
		 
			for v = 1 to num_tverts do
			(
				vert = getTVert tmesh v
				format "% % %\n" vert.x vert.y vert.z to:out_file
			)
		 
			format "\n" to:out_file
			for f = 1 to num_faces do
			(
				face = getFace tmesh f
				format "%\t%\t%\t\t" ((face.x - 1) as Integer) \
					((face.y - 1) as Integer) \
					((face.z - 1) as Integer) to:out_file
				face = getTVFace tmesh f
				format "%\t%\t%\n" ((face.x - 1) as Integer) \
					((face.y - 1) as Integer) \
					((face.z - 1) as Integer) to:out_file
			)
			delete tmesh
		)
	)
	close out_file
	
)